<!DOCTYPE html>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<link rel="stylesheet" href="../css/demo.css" />
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<!--
        	作者：offline
        	时间：2019-05-29
        	描述：view层
        -->
		<div id="app">
			<p>{{message}}</p>
			<input type="text" v-model="message" />
			<p><button v-on:click="greet">Greet</button></p>
			<p><button v-on:click="say('Hi')">Say</button></p>
		</div>
		<div id="app1">
			<fieldset>
				<legend>Create new person</legend>
				<div class="form-group">
					<label>Name:</label>
					<input type="text" v-model="newPerson.name" />
				</div>
				<div class="form-group">
					<label>Age:</label>
					<input type="text" v-model="newPerson.age" />
				</div>
				<div class="form-group">
					<label>Sex:</label>
					<select v-model="newPerson.sex">
						<option value="Male">Male</option>
						<option value="Female">Female</option>
					</select>
				</div>
				<div class="form-group">
                    <label></label>
                    <button @click="createPerson">Create</button>
                </div>
			</fieldset>
			<table>
				<thead>
					<tr>
						<th>Name</th>
						<th>Age</th>
						<th>Sex</th>
						<th>Delete</th>
					</tr>
				</thead>
				<tbody :class="'text-center'">
					<tr v-for="(person,index) in Allpersons">
						<td>{{person.name}}</td>
						<td>{{person.age}}</td>
						<td>{{person.sex}}</td>
						<td><button @click="deletePerson(index)">Delete</button></td>
					</tr>
				</tbody>
			</table>
		</div>
	</body>
	<script>
		//model层
		var messageData={
			message:"chenbinghui"
		}
		//view-model层
		new Vue({
			el:"#app",
			data:messageData,
			methods:{
				greet:function(){
					alert(this.message)
				},
				say:function(mes){
					alert(mes)
				}
			}
		})
		var app1 = new Vue({
			el:"#app1",
			data:{
				newPerson: {
                    name: '',
                    age: 0,
                    sex: 'Male'
                },
                Allpersons:[{
                	name: 'chenbinghui',
                    age: 20,
                    sex: 'Male'
                },{
                	name: 'zhouqian',
                    age: 21,
                    sex: 'Female'
                }]
			},
			methods:{
				createPerson:function(){
					this.Allpersons.push(this.newPerson)
					this.newPerson={name:'',age:0,sex:'Male'}
				},
				deletePerson:function(ids){
					alert(ids)
					this.Allpersons.splice(ids)
				}
			}
		})
		
	</script>
</html>
